package laf.agents;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import laf.env.ObjectIdentifier;
import laf.env.Observation;

public class ObservationBase implements Iterable<Observation> {
	
	/**
	 * List of observations
	 * 
	 * List is used for future persistence and better storage in database.
	 */
	private List<Observation> observationList = new ArrayList<Observation>();

	public boolean add(Observation observation) {
		return observationList.add(observation);
	}
	
	// TODO Linear search! Maps can probably improve performance if needed
	public Observation get(long time, ObjectIdentifier objectId) {
		for (Observation observation : observationList) {
			if (observation.getTime() == time && observation.getObjectIdentifier().equals(objectId)) {
				return observation;
			}
		}
		return null;
	}

	public boolean contains(Observation observation) {
		return observationList.contains(observation);
	}
	
	// TODO Linear search! Maps can probably improve performance if needed
	public boolean contains(long time, ObjectIdentifier objectId) {
		for (Observation observation : observationList) {
			if (observation.getTime() == time && observation.getObjectIdentifier().equals(objectId)) {
				return true;
			}
		}
		return false;
	}

	public int indexOf(Observation observation) {
		return observationList.indexOf(observation);
	}

	public boolean isEmpty() {
		return observationList.isEmpty();
	}

	public int size() {
		return observationList.size();
	}

	public Iterator<Observation> iterator() {
		return observationList.iterator();
	}
	
	
}
